﻿<!--
    Copyright (C) 2011 Ari Rokosa, Chinedu Eze, Johannes Virtanen,
                       Petri Tuononen, Timo Korkalainen

    This program is free software: you can redistribute it and/or modify
    it under the terms of the GNU General Public License as published by
    the Free Software Foundation, either version 3 of the License, or
    (at your option) any later version.

    This program is distributed in the hope that it will be useful,
    but WITHOUT ANY WARRANTY; without even the implied warranty of
    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
    GNU General Public License for more details.

    You should have received a copy of the GNU General Public License
    along with this program.  If not, see <http://www.gnu.org/licenses/>.
-->
 @{Layout = null;}
<div id="chat-up-button" class="button-small"></div>
<div id="chat-down-button" class="button-small"></div>

<script type="text/javascript">
    function chat_toggle() { $('#chat-up-button').toggle(); $('#chat-down-button').toggle(); }

    $('#chat-up-button').click(function () {
        chat_toggle();
        $('#chat-container').animate({ "top": "40%" }, 'fast');
    });

    $('#chat-down-button').click(function () {
        chat_toggle();
        $('#chat-container').animate({"top": "75%"}, 'fast');
    });
</script>

<script type="text/javascript">
    function refreshChat()
    {
        $.post("Chat/RenderMessagesHttpPost", function (data) {
            $('#chat-list').html(data);
        });
    }

    var chatRefreshId = setInterval("refreshChat()", 4000);
    
    $(document).ready(refreshChat());

    function clearChatInput() {
        $('#chat-input').val("");
    }
</script>

@using (Ajax.BeginForm("SendMessage", "Chat", new AjaxOptions {UpdateTargetId="chat-list", InsertionMode=InsertionMode.Replace, HttpMethod="post", OnBegin="clearChatInput" }))
{
    <div id="chat-add-box">
        <input id="chat-submit" class="button-small" type="submit" value="" maxlength="160" />
        @Html.TextBox("message", " ", new { id="chat-input"})
    </div>
}

<div id="chat-list">
</div>